﻿#pragma once
#include <QObject>
#include "MqttInfoEntity.h"
#include "SubTopicInfoEntity.h"
#include "PubTopicInfoEntity.h"
#include <QList>

class AppConfigDB : public QObject
{
	Q_OBJECT
public:
	AppConfigDB(QObject *parent = nullptr);
	~AppConfigDB();

	// singleton
	static AppConfigDB *getInstance()
	{
		static AppConfigDB instance;
		return &instance;
	}

private:
	bool initDB();

public:
	QList<MqttInfoEntity> getMqttInfoList();
	bool addMqttInfo(const MqttInfoEntity &entity);
	bool updateMqttInfo(const MqttInfoEntity &entity);
	bool addOrUpdateMqttInfoByName(const MqttInfoEntity &entity);
	bool deleteMqttInfoByName(const QString &name);
	bool getMqttInfoByName(const QString &name, MqttInfoEntity &entity);

	QList<SubTopicInfoEntity> getSubTopicInfoListByName(const QString &name);
	bool saveSubTopicInfoListByName(const QString &name, const QList<SubTopicInfoEntity> &list);
	bool modifySubTopicInfo(const SubTopicInfoEntity &entity);
	bool removeSubTopicInfo(const SubTopicInfoEntity &entity);
	bool addSubTopicInfo(const SubTopicInfoEntity &entity);
	bool addOrUpdateSubTopicInfo(const SubTopicInfoEntity &entity);

	QList<PubTopicInfoEntity> getPubTopicInfoListByName(const QString &name);
	bool savePubTopicInfoListByName(const QString &name, const QList<PubTopicInfoEntity> &list);
	bool modifyPubTopicInfo(const PubTopicInfoEntity &entity);
	bool removePubTopicInfo(const PubTopicInfoEntity &entity);
	bool addPubTopicInfo(PubTopicInfoEntity &entity);
	bool addOrUpdatePubTopicInfo(PubTopicInfoEntity &entity);
};
